package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.DangerChemicalQueryDetailedList;
import com.ruoyi.system.mapper.DangerChemicalQueryDetailedListMapper;
import com.ruoyi.system.service.IDangerChemicalQueryDetailedListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (DangerChemicalQueryDetailedList)表服务实现类
 *
 * @author makejava
 * @since 2022-11-14 17:38:22
 */
@Service
public class DangerChemicalQueryDetailedListServiceImpl implements IDangerChemicalQueryDetailedListService {
    @Autowired
    private DangerChemicalQueryDetailedListMapper dangerChemicalQueryDetailedListDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public DangerChemicalQueryDetailedList queryById(Integer id) {
        return this.dangerChemicalQueryDetailedListDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param dangerChemicalQueryDetailedList 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<DangerChemicalQueryDetailedList> queryByPage(DangerChemicalQueryDetailedList dangerChemicalQueryDetailedList, PageRequest pageRequest) {
        long total = this.dangerChemicalQueryDetailedListDao.count(dangerChemicalQueryDetailedList);
        return new PageImpl<>(this.dangerChemicalQueryDetailedListDao.queryAllByLimit(dangerChemicalQueryDetailedList, pageRequest), pageRequest, total);
    }

    @Override
    public List<DangerChemicalQueryDetailedList> list(DangerChemicalQueryDetailedList request) {
        return dangerChemicalQueryDetailedListDao.queryAll(request);
    }

    /**
     * 新增数据
     *
     * @param dangerChemicalQueryDetailedList 实例对象
     * @return 实例对象
     */
    @Override
    public DangerChemicalQueryDetailedList insert(DangerChemicalQueryDetailedList dangerChemicalQueryDetailedList) {

        dangerChemicalQueryDetailedList.setCreatedBy(SecurityUtils.getLoginUser().getUsername());
        dangerChemicalQueryDetailedList.setCreatedDate(new Date());
        dangerChemicalQueryDetailedList.setModifyBy(SecurityUtils.getLoginUser().getUsername());
        dangerChemicalQueryDetailedList.setModifyDate(new Date());

        this.dangerChemicalQueryDetailedListDao.insert(dangerChemicalQueryDetailedList);
        return dangerChemicalQueryDetailedList;
    }

    /**
     * 修改数据
     *
     * @param dangerChemicalQueryDetailedList 实例对象
     * @return 实例对象
     */
    @Override
    public DangerChemicalQueryDetailedList update(DangerChemicalQueryDetailedList dangerChemicalQueryDetailedList) {
        this.dangerChemicalQueryDetailedListDao.update(dangerChemicalQueryDetailedList);
        return this.queryById(dangerChemicalQueryDetailedList.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.dangerChemicalQueryDetailedListDao.deleteById(id) > 0;
    }
}
